﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Data.Common.QueryBuilder
{
    public class DbQueryOrderBy
    {
        public enum OrderBy
        {
            ASC = 0,
            DESC
        }
        public DbQuerySelect EndOrderBy;
        private List<String> OrderObjects;

        public DbQueryOrderBy(DbQuerySelect parent)
        {
            this.EndOrderBy = parent;
            this.OrderObjects = new List<String>();
        }

        public virtual DbQueryOrderBy AddColumn(OrderBy order, params String[] columns)
        {
            this.OrderObjects.AddRange(columns.Select(a => String.Concat(a, " ", order)));
            return this;
        }

        public override string ToString()
        {
            return this.OrderObjects.Count > 0 ? String.Concat("ORDER BY ", String.Join(", ", this.OrderObjects)) : String.Empty;
        }
    }
}
